package sample;

import javafx.embed.swing.SwingFXUtils;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;


import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class TestBuff {
    public static BufferedImage resizeImage(BufferedImage  originalImage, double times){
        int width = (int)(originalImage.getWidth()*times);
        int height = (int)(originalImage.getHeight()*times);

        int tType = originalImage.getType();
        if(0 == tType){
            tType = 5;
        }
        BufferedImage newImage = new BufferedImage(width,height, tType);
        Graphics g = newImage.getGraphics();
        g.drawImage(originalImage, 0,0,width,height,null);
        g.dispose();

        return newImage;
    }
//    public static void main(String [] args){
//        String relativePath = "E:\\第二阶段素材\\白富美密码锁\\vivo\\vigour_btn_default_normal_light.9.png";
//        NinePatch ninePatch = loadNinePatch(new File(relativePath));
//
//        javafx.scene.canvas.Canvas canvas = new Canvas(2000,2000);
//        BufferedImage bufferedImage = ninePatch.getImage();
//        WritableImage writableImage = SwingFXUtils.toFXImage(resizeImage(bufferedImage,2), new WritableImage(bufferedImage.getWidth(), bufferedImage.getHeight()));
//        ImageView imageView = new ImageView();
//    }
    public static NinePatch loadNinePatch(File file) {
        try {
            InputStream stream = new FileInputStream(file);
            NinePatch ninePatch = NinePatch.load(stream, true, false);
            stream.close();
            return ninePatch;
        } catch (IOException e) {
            System.err.println("An error occurs during loading.");
            e.printStackTrace();
            return null;
        }
    }

}
